package com.yhsoft.buyer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yhsoft.buyer.controller.request.DeliveryInVo;
import com.yhsoft.buyer.controller.request.VenderOrdersInVo;
import com.yhsoft.buyer.controller.response.VenderOrdersOutVo;
import com.yhsoft.buyer.service.IBuyerOrderService;
import com.yhsoft.common.response.PageResult;
import com.yhsoft.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author: yyyyyyyh
 * @create: 2023-11-20
 * @Version 1.0
 **/
@Api(tags = {"J-供货商订单管理"})
@RestController
@RequestMapping("/venderOrders")
public class VendorOrderController {
    @Autowired
    private IBuyerOrderService iBuyerOrderService;

    @ApiOperation("订单管理")
    @GetMapping("/list")
    public Result<PageResult<VenderOrdersOutVo>> getOrderList(VenderOrdersInVo inVo,
                                                              @RequestParam(value = "pageNo") Long pageNo,
                                                              @RequestParam(value = "pageSize") Long pageSize) {
        IPage<VenderOrdersOutVo> iPage = iBuyerOrderService.getOrderList(inVo, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("发货")
    @PostMapping("/delivery")
    public Result<?> delivery(@Valid @RequestBody DeliveryInVo inVo) {
        String msg = iBuyerOrderService.delivery(inVo);
        if (msg.equals("success")) {
            return Result.success(msg);
        }
        return Result.fail(msg);
    }

    @ApiOperation("新增订单趋势")
    @GetMapping("/get")
    public Result< List<Map<String, Object>>> get() {
        List<Map<String, Object>> line = iBuyerOrderService.getLine();
        return Result.success(line);
    }
}
